/*
 * uefi_helper.h
 *
 * UEFI helper header.
 */

#ifndef __HELPER_H__
#define __HELPER_H__

#include <stdarg.h>
#include <stdint.h>
#include <uefi.h>

#define DEBUG 1
// chang edk2 entry to clang-efi entyr
#ifndef EDK2_ENTYR
#define UefiMain efi_main
#endif 

extern EFI_GUID gEfiFileInfoGuid;
extern EFI_GUID LoadedImageProtocol;
extern EFI_GUID gLoadedImageProtocol;
extern EFI_GUID gEfiGraphicsOutputProtocolGuid;
extern EFI_GUID gEfiSimpleFileSystemProtocolGuid;
extern EFI_GUID gEfiSerialIoProtocolGuid;
extern EFI_GUID gLoadedImageProtocolGuid;
extern EFI_GUID gEfiLoadedImageProtocolGuid;
extern EFI_GUID gEfiAcpiTableGuid;

extern EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *GOut;
extern EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *GStderr;
extern EFI_HANDLE GImagehandle;
extern EFI_SYSTEM_TABLE *ST;
extern EFI_RUNTIME_SERVICES *RT;
extern EFI_BOOT_SERVICES *BS;
#define gST ST
#define gRT RT
#define gBS BS

#define UEFI_STREAN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL

// acsii print
void print(const char *fmt, ...);
void println(const char *fmt, ...);
void eprint(const char *fmt, ...);
void eprintln(const char *fmt, ...);
void fprint(UEFI_STREAN *out, const char *fmt, ...);
// utf print
void Print(const uint16_t *fmt, ...);
void Println(const uint16_t *fmt, ...);
void EPrint(const uint16_t *fmt, ...);
void EPrintln(const uint16_t *fmt, ...);
void FPrint(UEFI_STREAN *out, const uint16_t *fmt, ...);
void CleanScreen();

EFI_STATUS init_helper(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table);
EFI_STATUS StatusOut(EFI_STATUS status);
int64_t CompareGuid(EFI_GUID *Guid1, EFI_GUID *Guid2);

/*
 ***********************************************************
 *
 *             uefi helper-lib
 *
 * *********************************************************
 */

#ifndef UEFI_HELPER_LIB
#define UEFI_HELPER_LIB
int isdigit(int code);
int isalpha(int code);
int isalnum(int code);
int is_space(int code);
size_t strlen(const char *str);
size_t wcslen(const uint16_t *str);
void *memcpy(void *dst, const void *src, size_t size);
void *memset(void *ptr, int value, size_t size);
int strcmp(const char *l, const char *r);
char *strncpy(char *dst, const char *src, size_t size);
uint16_t *wcsncpy(uint16_t *dst, const char *src, size_t size);
#endif

#ifdef _STDLIB_H_
#undef UEFI_HELPER_LIB
#endif

#ifdef _STDLIB_H__
#undef UEFI_HELPER_LIB
#endif

#endif // __HELPER_H__
